Fix crate_types in serialized targets
authorAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 24 Mar 2017 07:40:12 +0000 (10:40 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 24 Mar 2017 07:40:12 +0000 (10:40 +0300)
src/cargo/core/manifest.rs
tests/metadata.rs

index 24cfd4d42f4367e9d4f9806330dd0c63c8ddd377..ad9a129aff4e33e1d613a38322229dd3bc1d8e3d 100644 (file)
@@ -112,23 +112,6 @@ pub enum TargetKind {
     CustomBuild,
 }
 
-impl TargetKind {
-    /// Returns a vector of crate types as specified in a manifest
-    pub fn crate_types(&self) -> Vec<&str> {
-        use self::TargetKind::*;
-        match *self {
-            Lib(ref kinds) | ExampleLib(ref kinds) => {
-                kinds.iter().map(LibKind::crate_type).collect()
-            }
-            Bin => vec!["bin"],
-            ExampleBin => vec!["example"],
-            Test => vec!["test"],
-            CustomBuild => vec!["custom-build"],
-            Bench => vec!["bench"]
-        }
-    }
-}
-
 impl ser::Serialize for TargetKind {
     fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
         where S: ser::Serializer,
@@ -207,7 +190,11 @@ pub struct Target {
 
 #[derive(Serialize)]
 struct SerializedTarget<'a> {
+    /// Is this a `--bin bin`, `--lib`, `--example ex`?
+    /// Serialized as a list of strings for historical reasons.
     kind: &'a TargetKind,
+    /// Corresponds to `--crate-type` compiler attribute.
+    /// See https://doc.rust-lang.org/reference.html#linkage
     crate_types: Vec<&'a str>,
     name: &'a str,
     src_path: &'a PathBuf,
@@ -217,7 +204,7 @@ impl ser::Serialize for Target {
     fn serialize<S: ser::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
         SerializedTarget {
             kind: &self.kind,
-            crate_types: self.kind.crate_types(),
+            crate_types: self.rustc_crate_types(),
             name: &self.name,
             src_path: &self.src_path,
         }.serialize(s)
index 31332639104ba2f17dc3403bef0c4a8763d365d7..04216a39d22c7f49d7a603f13ce7edc576df7f64 100644 (file)
@@ -308,7 +308,7 @@ name = "ex"
                     },
                     {
                         "kind": [ "example" ],
-                        "crate_types": [ "example" ],
+                        "crate_types": [ "bin" ],
                         "name": "ex",
                         "src_path": "[..][/]foo[/]examples[/]ex.rs"
                     }